package com.commonfunction;

import java.awt.List;
import java.util.HashMap;

import com.databasefunction.AllDBFunction;

public class CommFunction {
	public List getCustomerNames(String initials){
		List custList = new List();
		custList.add("item1");
		custList.add("item2");
		System.out.println(custList.getItem(1));
		return custList;
	}
	
	public CommData getDataMap(String name){
		CommData commData = new CommData();
		return commData;
	}
	
	public String getAddress(String name){
		//Call database
		return name;
	}
	
	public boolean isCustomerpresent(String cname){
		//call db
		return true;
	}
	
	public boolean isBrokerPresent(String bname){
		//call db
		return true;
	}
	
	public boolean isCommitionagentPresent(String cagenName){
		//call db
		return true;
	} 
	
	public HashMap getSecurityQuestions(String user){
		//call db
		
		HashMap quedata = new HashMap();
		quedata.put("question1", "question1");
		quedata.put("ans1", "ans1");
		quedata.put("question2", "Question2");
		quedata.put("ans2", "ans2");
		return quedata;
	}
	
	public String getUniqueId(String username){
		//Call db
		AllDBFunction allDBFunction = new AllDBFunction();
		//allDBFunction.
		String uniqId = allDBFunction.getUniquDealerId(username);
		return uniqId;
				
	}
	
	public boolean isDealerPresent(String name){
		AllDBFunction allDBFunction = new AllDBFunction();
		boolean result = allDBFunction.isdealerexists(name);
		return result;
	}
	
	public boolean isBarcodePresent(String name){
		AllDBFunction allDBFunction = new AllDBFunction();
		boolean result = allDBFunction.isBarcodeExists(name);
		return result;
	}
	
	public boolean isBarcodePresentFromAnalysisReopt(String name){
		AllDBFunction allDBFunction = new AllDBFunction();
		boolean result = allDBFunction.isBarcodeExistsInAnalysis(name);
		return result;
	}
	
	public boolean isUserExist(String user){
		boolean ispresent = false;
		return ispresent;
	}
	
	public boolean addUser(String user,String pass,String role){
		return true;
	}
	
	public HashMap getAnalysisList(){
		HashMap datamap = new HashMap();
		datamap.put("barcode1", "Y");
		datamap.put("barcode2", "N");
		datamap.put("barcode3", "Y");
		datamap.put("barcode4", "N");
		AllDBFunction allDBFunction = new AllDBFunction();
		datamap = allDBFunction.getAnalysisList();		
		return datamap;
	}
	
	public HashMap getBarcodeData(String barcode){
	
		HashMap hm1 = new HashMap();
		HashMap hm = new HashMap();
		/*
		hm1.put("businessBrokerName", "BROKER1");
		hm1.put("businesscustomerName", "CUST1");
		hm1.put("businessCommisionAgentName", "COMMAGNT1");
		hm1.put("businessRSTNo", "RST1");
		hm1.put("businessVehicleNo", "VEHICLE1");
		hm1.put("businessCommodity", "COMODITY1");
		hm1.put("businessNoOfBags", "10");
		hm1.put("businessPONo", "PONO1");
		hm1.put("businessGrossWeight", "10");
		hm1.put("businessTareWeight", "10");
		hm1.put("businessNetWeight", "10");
		hm1.put("businessdate", formatDate("19891122"));

		hm1.put("businessRate", "10");
		hm1.put("businessGrossAmount", "100");
		hm1.put("businessLessRebate", "101");
		hm1.put("businesscashDiscount", "102");
		hm1.put("businessAdvance", "12000");

		hm1.put("businessTotalRebate", "8500");
		hm1.put("businessTotalPaid", "12000");
		hm1.put("businessWeighingMachineUser", "WEIGHTMACHINEUSER");
		hm1.put("businessLabUser", "LABUSER1");

		hm1.put("businessDamageSeeds", "10");
		hm1.put("businessSandSilica", "20");
		hm1.put("businessMoisture", "15");
		hm1.put("businessExcessDamage", "5");
		hm1.put("businessExcessSandSilica", "20");
		hm1.put("businessExcessMoisture", "2");
		hm1.put("businessDamageAmountCut", "DamageAmmtCut1");
		hm1.put("businessSandSilicaAmountCut", "SandSilicaCut1");
		hm1.put("businessMoistureAmountCut", "MoistureCut1");
		hm1.put("businessUnloading", "Unloading1");
		hm1.put("businessAddDalali", "AddDalali1");
		hm1.put("businessHide", "YES");

		hm.put("BARCODE1", hm1);*/
		AllDBFunction allDBFunction = new AllDBFunction();
		hm = allDBFunction.getBarcodeInfo(barcode);
		
		return hm;

	}
	
	public String formatDate(String date){
		//String dateFormated="19891122"";
		String dateFormated="";
		dateFormated = date.substring(0,4)+"-"+date.substring(4,6)+"-"+date.substring(6,8);
		System.out.println(dateFormated);
		return dateFormated;
	}
	
	public int formatDateForDb(String date){
		//String dateFormated="19891122"";
		int dateFormated = 0;
		if (null!=date && !date.equals("")) {
			dateFormated = 0;
			dateFormated = Integer.parseInt(date.replace("-", ""));
		}
		
		return dateFormated;
	}
	
	public boolean isCityOrDistPresent(String name,int cityordist){
		AllDBFunction allDBFunction = new AllDBFunction();
		boolean result = allDBFunction.isCityOrDistPresent(name, cityordist);
		return result;
	}
}
